;Copyright (C) 2010 Salil Bhagurkar

;This file is part of k3

;k3 is free software: you can redistribute it and/or modify
;it under the terms of the GNU Lesser General Public License as published by
;the Free Software Foundation, either version 3 of the License, or
;(at your option) any later version.

;k3 is distributed in the hope that it will be useful,
;but WITHOUT ANY WARRANTY; without even the implied warranty of
;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;GNU Lesser General Public License for more details.

;You should have received a copy of the GNU Lesser General Public License
;along with k3.  If not, see <http://www.gnu.org/licenses/>.

[bits 32]
[segment .text]
;Processor interrupt control functions

global _cli
_cli:
cli
ret

global _sti
_sti:
sti
ret

global __interrupt_flag
__interrupt_flag:
pushf
pop eax
and eax,512
shr eax,9
ret


extern setvect
%macro setvector 1-2
mov ecx,%2
mov edx,%1
call setvect
%endmacro


global __set_all_irqs
__set_all_irqs:
setvector 0x20,irq0
setvector 0x21,irq1
setvector 0x22,irq2
setvector 0x23,irq3
setvector 0x24,irq4
setvector 0x25,irq5
setvector 0x26,irq6
setvector 0x27,irq7
setvector 0x28,irq8
setvector 0x29,irq9
setvector 0x2a,irq10
setvector 0x2b,irq11
setvector 0x2c,irq12
setvector 0x2d,irq13
setvector 0x2e,irq14
setvector 0x2f,irq15
ret


extern _uirq0
extern _uirq1
extern _uirq2
extern _uirq3
extern _uirq4
extern _uirq5
extern _uirq6
extern _uirq7
extern _uirq8
extern _uirq9
extern _uirq10
extern _uirq11
extern _uirq12
extern _uirq13
extern _uirq14
extern _uirq15

;Default handler for all the irqs
default_hnd:
ret

arch_irq_call_ptr dd default_hnd

global _arch_set_irq_call;(fnptr)
_arch_set_irq_call:
	push ebp
	mov ebp,esp
	mov eax,[ebp+8]
	mov [arch_irq_call_ptr],eax
	mov eax,0
	pop ebp
ret

%macro irq_function 1
irq%1:
	pusha
	push %1
	call [arch_irq_call_ptr]
	add esp,4
	popa
iret
%endmacro


irq_function 0
irq_function 1
irq_function 2
irq_function 3
irq_function 4
irq_function 5
irq_function 6
irq_function 7
irq_function 8
irq_function 9
irq_function 10
irq_function 11
irq_function 12
irq_function 13
irq_function 14
irq_function 15
